package sg.edu.nus.iss.umpire.service.competition;

import sg.edu.nus.iss.umpire.dao.CompetitionDao;
import sg.edu.nus.iss.umpire.dao.jpa.CompetitionDaoImpl;
import sg.edu.nus.iss.umpire.support.HttpMethod;
import sg.edu.nus.iss.umpire.support.Service;
import sg.edu.nus.iss.umpire.support.ServiceConfig;
import sg.edu.nus.iss.umpire.support.ServiceContext;

@ServiceConfig(path = "competitions/delete", method = HttpMethod.POST)
public class DeleteCompetitionService implements Service{

    @Override
    public String serve(ServiceContext ctx) throws Exception {
		String[] keys = ctx.getRequest().getParameter("keys").split(",");
		CompetitionDao dao = new CompetitionDaoImpl(ctx.getEntityManager());
		for (String keyStr : keys) {
			dao.deleteByKey(Long.valueOf(keyStr));
		}
		return null;
    }

}
